package com.gogowan.agroenterprise.widget.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.gogowan.agroenterprise.R;
import com.gogowan.agroenterprise.model.BoxCode;
import com.gogowan.agroenterprise.model.StoreModel;

/**
 * 仓库spinner adapter
 * 
 * @author tjh 2017-01-13
 *
 */
public class XMListViewAdapter extends BaseAdapter {
	private Context mContext;
	private List<BoxCode> boxCodeList;

	public XMListViewAdapter(Context mContext, List<BoxCode> boxCodeList) {
		this.mContext = mContext;
		this.boxCodeList = boxCodeList;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return boxCodeList.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return boxCodeList.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return boxCodeList.get(position).getStoreId();
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder viewHolder = null;
		if (convertView == null) {
			viewHolder = new ViewHolder();
			convertView = LayoutInflater.from(mContext).inflate(
					R.layout.activity_xm_listview_item, null);
			viewHolder.xmmcText = (TextView) convertView
					.findViewById(R.id.xm_listview_cpmc_text);
			viewHolder.xmbhText = (TextView) convertView
					.findViewById(R.id.xm_listview_xmbh_text);
			viewHolder.zxrqText = (TextView) convertView
					.findViewById(R.id.xm_listview_zxrq_text);
			convertView.setTag(viewHolder);
		} else {
			viewHolder = (ViewHolder) convertView.getTag();
		}

		viewHolder.xmmcText
				.setText(boxCodeList.get(position).getMaterialName());
		viewHolder.xmbhText.setText(boxCodeList.get(position).getCode());
		viewHolder.zxrqText.setText(boxCodeList.get(position).getPackDate());

		return convertView;
	}

	class ViewHolder {
		TextView xmmcText;
		TextView xmbhText;
		TextView zxrqText;
	}

}
